/**
 * 获取url链接中的参数
 * @param {*} name 
 * @returns 
 */
const getUrlParameterXDC = (name) => {
    name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
    var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
    var results = regex.exec(location.hash);
    return results === null
        ? ''
        : decodeURIComponent(results[1].replace(/\+/g, ' '));
}

/**
 * 获取url链接中的单个参数
 * @returns 
 */
const queryObj = () => {
    const str = location.search
    if (str) {
        let url = str.substr(1),
            arr = url.split('&'),
            len = arr.length,
            i = 0,
            request = {}
        for (; i < len; i++) {
            request[arr[i].split('=')[0]] = arr[i].split('=')[1]
        }
        return request
    } else {
        return {}
    }
}

/**
 * 获取url中某个参数的值
 * @param {*} strName ：被传入的参数
 * @returns 传入参数strName的value
 */
const getOneUrlParam = (strName) => {
    var strHref = document.location.toString();
    var intPos = strHref.indexOf("?");
    var strRight = strHref.substr(intPos + 1); // 获取到右边的参数部分
    var arrTmp = strRight.split("&"); // 以&分割成数组
    //===========循环数组
    for (var i = 0; i < arrTmp.length; i++) {
        var dIntPos = arrTmp[i].indexOf("=");
        var paraName = arrTmp[i].substr(0, dIntPos);
        var paraData = arrTmp[i].substr(dIntPos + 1);
        if (paraName.toUpperCase() == strName.toUpperCase()) {
            return paraData;
        }
    }
    return "";
}

export {
    getUrlParameterXDC,
    queryObj,
    getOneUrlParam
}